package com.search.controller;

import com.common.domain.vo.SearchQueryByKeywordResultVO;
import com.common.result.Result;
import com.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 路亚
 * @version 0.1
 * @className SearchController
 * @description
 * @date 2024/12/20 15:37
 * @since jdk11
 */
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "搜索管理")
public class SearchController {

    private final SearchService searchService;

    @GetMapping("/byKeyword")
    @ApiOperation("根据关键字搜索")
    /**
     * 通过关键字搜索 短剧名称 字段，同时让 收藏数 参与评分的计算
     * 分页查询，默认一页 10 条
     */
    public Result queryByKeyword(String keyword, Integer page) {
        SearchQueryByKeywordResultVO result = searchService.queryByKeyword(keyword, page);
        return new Result(200, "查询成功", result);
    }

    @GetMapping("/byTags")
    @ApiOperation("根据标签搜索")
    public Result queryByTags(String tags, Integer page) {
        SearchQueryByKeywordResultVO  result = searchService.queryByTags(tags, page);
        return new Result(200, "查询成功", result);
    }

    @GetMapping("/byActor")
    @ApiOperation("根据演员搜索")
    // gender=1表示男演员，gender=0表示女演员，
    public Result queryByActor(String name, Integer gender, Integer page) {
        log.info("根据演员搜索,name:{},gender:{}", name, gender);
        SearchQueryByKeywordResultVO  result = searchService.queryByActor(name, gender, page);
        return new Result(200, "查询成功", result);
    }
}
